import 'package:extended_keyboard/extended_keyboard.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:get/get.dart';
import 'package:study_demo/base/BaseController.dart';

import '../../../../widgets/my_extended_text_selection_controls.dart';

class ExtendTextFieldController extends BaseController {
  final ScrollController scrollController = ScrollController();

  final CustomKeyboardController customKeyboardController =
      CustomKeyboardController(KeyboardType.system);

  final TextEditingController textEditingController = TextEditingController();

  final MyTextSelectionControls _myExtendedMaterialTextSelectionControls =
      MyTextSelectionControls();

  final sessions = <String>[
    '[44] @Dota2 CN dota best dota',
    'yes, you are right [36].',
    '大家好，我是拉面，很萌很新 [12].',
    '\$Flutter\$. CN dev best dev',
    '\$Dota2 Ti9\$. Shanghai,I\'m coming.',
    'error 0 [45] warning 0',
  ].obs;

  void sendMessage(String text) {
    if (text.isEmpty) {
      return;
    }

    sessions.insert(0, text);

    SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) {
      scrollController.animateTo(
        scrollController.position.minScrollExtent,
        duration: const Duration(milliseconds: 200),
        curve: Curves.easeInOut,
      );
    });
  }
}
